#ifndef __BEHAVIOR_TREE_H__
#define __BEHAVIOR_TREE_H__

#include <behaviortree_cpp/bt_factory.h>

#include <iostream>
#include <string>
#include <vector>

// 条件节点：检查是否下雨
class IsRaining : public BT::ConditionNode
{
  public:
    IsRaining(const std::string& name, const BT::NodeConfiguration& config)
        : BT::ConditionNode(name, config)
    {
    }

    static BT::PortsList providedPorts()
    {
        return {BT::InputPort<bool>("is_raining")};  // 声明输入端口
    }

    BT::NodeStatus tick() override
    {
        auto res = getInput<bool>("is_raining");
        if (!res)
        {
            throw BT::RuntimeError("missing is_raining input");
        }
        bool is_raining = res.value();
        std::cout << "[条件] 天气状态: " << (is_raining ? "下雨" : "晴天") << "\n";
        return is_raining ? BT::NodeStatus::SUCCESS : BT::NodeStatus::FAILURE;
    }
};

// 动作节点：宅家
class StayHome : public BT::SyncActionNode
{
  public:
    StayHome(const std::string& name) : BT::SyncActionNode(name, {}) {}
    BT::NodeStatus tick() override
    {
        std::cout << "[动作] 下雨了，躺平追剧！\n";
        return BT::NodeStatus::SUCCESS;
    }
};

// 动作节点：出门
class GoOut : public BT::SyncActionNode
{
  public:
    GoOut(const std::string& name) : BT::SyncActionNode(name, {}) {}
    BT::NodeStatus tick() override
    {
        std::cout << "[动作] 天气晴朗，出门散步！\n";
        return BT::NodeStatus::SUCCESS;
    }
};

void testBehaviorTree();

#endif  // __BEHAVIOR_TREE_H__